<?php
//select * from hy_mealorder ml left join hy_product pr on ml.product_id=pr.product_id where pr.product_id=44
namespace Client\Table;

use Zend\Db\Sql\Select;
//use Zend\Db\Sql\Where;

class MealOrderTable extends CommonTable{
	protected $table = 'hy_mealorder';
	protected $id = 'id';
	
	public function getItems($query){
		
		$select = new Select(array('ml'=>$this->getTable()));
		//$select->columns(array("id","s1","s2","s3","s4","s5","s6","s7","d1","d2","d3","d4","d5","d6","d7","type"));
		$select->columns(array("id","s1"=>"w1","s2"=>"w2","s3"=>"w3","s4"=>"w4","s5"=>"w5","s6"=>"w6","s7"=>"w7","d1"=>"w8","d2"=>"w9","d3"=>"w10","d4"=>"w11","d5"=>"w12","d6"=>"w13","d7"=>"w14","type"));
		
		$select->join(array("pr"=>"hy_product"),"ml.product_id=pr.product_id",array('org_id','product_id','product_name',
				'product_price','product_thumb_image','product_description','product_big_image'),$select::JOIN_LEFT);
		
		//$select->where(array("pr.product_id"=>44));
		//if($query['org_id']){
		//	$select->where(array("pr.org_id"=>$query['org_id']));
		//}
		
		$rowset = $this->selectWith($select);
		$row=$rowset->toArray();
		return $row;
		
	}
	
	public function getItem($id){
		$select = new Select(array('ml'=>$this->getTable()));
		$select->columns(array("id","s1"=>"w1","s2"=>"w2","s3"=>"w3","s4"=>"w4","s5"=>"w5","s6"=>"w6","s7"=>"w7","d1"=>"w8","d2"=>"w9","d3"=>"w10","d4"=>"w11","d5"=>"w12","d6"=>"w13","d7"=>"w14","type"));
		
		$select->join(array("pr"=>"hy_product"),"ml.product_id=pr.product_id",array('org_id','product_id','product_name','product_price'),$select::JOIN_LEFT);
		$select->where(array("ml.id"=>$id));
		
		$rowset = $this->selectWith($select);
		
		$row=$rowset->current();
		
		return $row;
	}
	
}